#include "cardinteraction.h"
#include <glut.h>
#include <QKeyEvent>

#include "BirdEagleGame.h"
#include "testkinect.h"


CardInteraction::CardInteraction(QWidget *parent)
	: BaseApplication(parent)
{
	
}

CardInteraction::~CardInteraction()
{
	if (mCatMouseGame)
	{
		delete mCatMouseGame;
		mCatMouseGame = 0;
	}
}


void CardInteraction::Init()
{
#ifdef BIRD_EAGLE
	mCatMouseGame = new BirdEagleGame(CAMERA_WIDTH, CAMERA_HEIGHT, std::string("cat_and_mouse.avi"));
#endif // CAT_MOUSE
}

void CardInteraction::initializeGL()
{
	glClearColor(0, 0, 0, 0);
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER,0.1f); 
	glShadeModel(GL_SMOOTH);  
	
	BaseApplication::initializeGL();
}


void CardInteraction::paintGL()
{
	glClearColor(0.f, 0.f, 0.f, 0.f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#ifdef BIRD_EAGLE
	mCatMouseGame->Render();
#endif // CAT_MOUSE
}


void CardInteraction::resizeGL(int width, int height)
{
	glViewport (0, 0, (GLsizei)(width), (GLsizei)(height));				// Reset The Current Viewport
	glMatrixMode (GL_PROJECTION);										// Select The Projection Matrix
	glLoadIdentity ();													// Reset The Projection Matrix
	gluPerspective (45.0f, (GLfloat)(width)/(GLfloat)(height),			// Calculate The Aspect Ratio Of The Window
		1.0f, 10000.0f);	
	glMatrixMode (GL_MODELVIEW);										// Select The Modelview Matrix
	glLoadIdentity ();													// Reset The Modelview Matrix

	//
}

void CardInteraction::Update()
{
#ifdef BIRD_EAGLE
	mCatMouseGame->Update(mElapsedTime);
#endif // CAT_MOUSE
	updateGL();
}

void CardInteraction::mouseDoubleClickEvent(QMouseEvent *e)
{
	if(!isFullScreen())
		showFullScreen();
	else
		showNormal();
}
void CardInteraction::keyPressEvent(QKeyEvent *e)
{
	if (e->key() == Qt::Key_Escape)
		close();
}